from HttpServer import RequestHandler, run_server, JsonResponseData,HttpResponseMaker


class DemoPostHandler(RequestHandler):
    """
    假设该请求完成一个加法的POST
    """

    def handler(self, _request: tuple):
        header, content = _request
        try:
            res = int(content['a'][0]) + int(content['b'][0])
            print("res=", res)
            return JsonResponseData({'ret': 0, 'res': res})
        except Exception as error:
            return JsonResponseData({'ret': 1, 'err': error.__str__()})


if __name__ == '__main__':
    DemoPostHandler('/add', 'POST')
    run_server()
